package htmodels

import (
	"github.com/astaxie/beego/orm"
	"travelservia/models"
)
func HTHomeAdd(home *models.Home) error {
	o := orm.NewOrm()
	_, err := o.Insert(home)
	return err
}

func HTHomeGetDetail(home *models.Home) error {
	o := orm.NewOrm()
	return o.Read(home)
}

func HTHomeGetCount(search string, searchFiled string , ManageType int) (int64, error) {
	o := orm.NewOrm()
	m := models.Home{}
	count, err := o.QueryTable(m.TableName()).Filter(m.FN_ManageType(), ManageType).Filter(searchFiled + "__icontains", search).Count()
	return count, err
}

func HTHomeGetList(homes *[]models.Home, fields []string , ManageType int, offset int64, limit int, search string, searchFiled string, orderby string) error {
	o := orm.NewOrm()
	m := models.Home{}
	_, err := o.QueryTable(m.TableName()).Filter(m.FN_ManageType(), ManageType).Filter(searchFiled + "__icontains", search).OrderBy(orderby).Offset(offset).Limit(limit).All(homes, fields...)
	return err
}

func HTHomeDelete(Ids []int64) (int64, error) {
	o := orm.NewOrm()
	m := models.Home{}
	count, err := o.QueryTable(m.TableName()).Filter("Id" + "__in", Ids).Delete()
	return count, err
}
func HTHomeUpdate(home *models.Home) error {
	o := orm.NewOrm()
	_, err := o.Update(home)
	return err
}